package cn.ieayinfo.train.mybooks.Web;

import cn.ieayinfo.train.mybooks.Entity.User;
import cn.ieayinfo.train.mybooks.Service.BookService;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

@Controller
public class MainController {
    @Resource
    private BookService bookService;

    @RequestMapping({"/", "/index"})
    public String index(ModelMap model) {
        User currentUser = (User) SecurityUtils.getSubject().getPrincipal();
        model.put("user", currentUser);
        if(currentUser != null) {
            model.put("books", bookService.getShareBookList());
        }
        return "index";
    }

    @RequestMapping("/403")
    public String unAuthorization() {
        return "403";
    }
}
